/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.HostGroup;
/*     */ import com.wgcloud.service.HostGroupService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/hostGroup"})
/*     */ public class HostGroupController
/*     */ {
/*  36 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.HostGroupController.class);
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HostGroupService hostGroupService;
/*     */ 
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String HostGroupList(HostGroup hostGroup, Model model, HttpServletRequest request) {
/*  56 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  58 */       PageInfo pageInfo = this.hostGroupService.selectByParams(params, Integer.valueOf(hostGroup.getPage().intValue()).intValue(), Integer.valueOf(hostGroup.getPageSize().intValue()).intValue());
/*  59 */       model.addAttribute("page", pageInfo);
/*  60 */       String msg = request.getParameter("msg");
/*  61 */       if (!StringUtils.isEmpty(msg)) {
/*  62 */         model.addAttribute("msg", "删除失败，机组已经被应用");
/*     */       } else {
/*  64 */         model.addAttribute("msg", "");
/*     */       } 
/*  66 */     } catch (Exception e) {
/*  67 */       logger.error("查询出错", e);
/*  68 */       this.logInfoService.save("HostGroupList", "查询机组列表错误：" + e.toString(), "1");
/*     */     } 
/*  70 */     return "hostGroup/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"add"})
/*     */   public String addHostGroup(HostGroup hostGroup, Model model) {
/*  82 */     return "hostGroup/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"save"})
/*     */   public String saveHostGroup(HostGroup hostGroup, Model model, HttpServletRequest request) {
/*     */     try {
/*  97 */       if (StringUtils.isEmpty(hostGroup.getId())) {
/*  98 */         this.hostGroupService.save(hostGroup);
/*     */       } else {
/* 100 */         HostGroup ho = this.hostGroupService.selectById(hostGroup.getId());
/* 101 */         ho.setRemark(hostGroup.getRemark());
/* 102 */         ho.setGroupName(hostGroup.getGroupName());
/* 103 */         this.hostGroupService.updateById(ho);
/*     */       }
/*     */     
/* 106 */     } catch (Exception e) {
/* 107 */       logger.error("保存机组错误：", e);
/* 108 */       this.logInfoService.save(hostGroup.getGroupName(), "保存机组错误：" + e.toString(), "1");
/*     */     } 
/* 110 */     return "redirect:/hostGroup/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String viewHostGroup(Model model, HttpServletRequest request) {
/* 123 */     String errorMsg = "查看机组错误：";
/* 124 */     String id = request.getParameter("id");
/* 125 */     HostGroup HostGroup = new HostGroup();
/*     */     try {
/* 127 */       HostGroup = this.hostGroupService.selectById(id);
/* 128 */       model.addAttribute("HostGroup", HostGroup);
/* 129 */     } catch (Exception e) {
/* 130 */       logger.error(errorMsg, e);
/* 131 */       this.logInfoService.save(HostGroup.getGroupName(), errorMsg + e.toString(), "1");
/*     */     } 
/* 133 */     return "hostGroup/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 147 */     String errorMsg = "删除机组信息错误：";
/* 148 */     String groupName = "";
/*     */     try {
/* 150 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 151 */         HostGroup HostGroup = this.hostGroupService.selectById(request.getParameter("id"));
/* 152 */         groupName = HostGroup.getGroupName();
/* 153 */         Map<String, Object> searchMap = new HashMap<>();
/* 154 */         searchMap.put("groupId", HostGroup.getId());
/* 155 */         int count = this.systemInfoService.countByParams(searchMap);
/* 156 */         if (count > 0) {
/* 157 */           this.logInfoService.save(groupName, "机组已经被应用，无法删除", "1");
/*     */         } else {
/* 159 */           this.hostGroupService.deleteById(request.getParameter("id").split(","));
/*     */         } 
/*     */       } 
/* 162 */     } catch (Exception e) {
/* 163 */       logger.error(errorMsg, e);
/* 164 */       this.logInfoService.save(groupName, errorMsg + e.toString(), "1");
/*     */     } 
/*     */     
/* 167 */     return "redirect:/hostGroup/list?msg=delErr";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/HostGroupController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */